home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Final Chance 1.0 Source / Final Chance ƒ / init code ƒ / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-13  |  3.2 KB  |  134 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        main.c
  4.  
  5. Purpose:    This module handles the actual shutdown proc -- creating
  6.             a grafport on the screen and showing the dialog box.
  7.             
  8.  
  9. Final Chance -=- a "do you really want to do this?" dialog on shutdown
  10. Copyright (c) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "init.h"
  30. #include "main.h"
  31. #include "globals.h"
  32.  
  33. Str255            gTheQuote;
  34. Handle            gChanceDitl;
  35. DialogTHndl        gChanceDlog;
  36.  
  37. void FinalChance(void)
  38. {
  39.     DialogTPtr        dtmp;
  40.     DialogRecord    dlog;
  41.     Handle            newDitl, itemH;
  42.     Rect            *theRect, box;
  43.     int                left, top, item, itemType;
  44.     KeyMap            theKeys;
  45.     
  46.     GetKeys(&theKeys);
  47.     if(theKeys[1] & 0x04)    /* option key down? */
  48.         return;
  49.     
  50.     SetUpA4();
  51.     
  52.     InitGraf(&thePort);
  53.     SetCursor(&arrow);
  54.     
  55.     HLock(gChanceDlog);
  56.     newDitl=gChanceDitl;
  57.     HandToHand(&newDitl);
  58.  
  59.     theRect = (Rect*) *gChanceDlog;
  60.     left = (screenBits.bounds.right - (theRect->right - theRect->left)) / 2;
  61.     top = (screenBits.bounds.bottom - (theRect->bottom - theRect->top)) / 3;
  62.     
  63.     if(top < (GetMBarHeight() + 1))
  64.         top = GetMBarHeight() + 1;
  65.     theRect->right += left - theRect->left;
  66.     theRect->left = left;
  67.     theRect->bottom += top - theRect->top;
  68.     theRect->top = top;
  69.  
  70.     dtmp=*gChanceDlog;
  71.     NewDialog(&dlog, theRect, dtmp->title, dtmp->visible, dtmp->procID,
  72.                 (WindowPtr)-1L, dtmp->goAwayFlag, dtmp->refCon, newDitl);
  73.     
  74.     ParamText(gTheQuote, "\p", "\p", "\p");
  75.     
  76.     GetDItem(&dlog, 6, &itemType, &itemH, &box);
  77.     InsetRect(&box, -4, -4);
  78.     SetDItem(&dlog, 6, itemType, (Handle)OutlineDefaultButton, &box);
  79.     
  80.     ShowWindow(&dlog);
  81.     
  82.     do { ModalDialog((ProcPtr)ProcOFilter, &item); } while ((item!=1) && (item!=2));
  83.     
  84.     HideWindow(&dlog);
  85.     CloseDialog(&dlog);
  86.     
  87.     HUnlock(gChanceDlog);
  88.     DisposeHandle(newDitl);
  89.     
  90.     RestoreA4();
  91.     
  92.     if (item==2)
  93.         ExitToShell();
  94. }
  95.  
  96. pascal Boolean ProcOFilter(DialogPtr theDialog, EventRecord *theEvent, short *theItem)
  97. {
  98.     unsigned char    theChar;
  99.     
  100.     switch (theEvent->what)
  101.     {
  102.         case keyDown:
  103.         case autoKey:
  104.             theChar=theEvent->message & charCodeMask;
  105.             if ((theChar==0x0d) || (theChar==0x03))
  106.             {
  107.                 *theItem=1;
  108.                 return TRUE;
  109.             }
  110.             if ((theChar==0x1b) ||
  111.                 ((theEvent->modifiers & cmdKey) && (theChar=='.')))
  112.             {
  113.                 *theItem=2;
  114.                 return TRUE;
  115.             }
  116.             break;
  117.     }
  118.     
  119.     return FALSE;
  120. }
  121.  
  122. pascal void OutlineDefaultButton(DialogPtr myDlog, short itemNum)
  123. {
  124.     short    itemType;
  125.     Handle    itemH;
  126.     Rect    box;
  127.     
  128.     GetDItem(myDlog, 1, &itemType, &itemH, &box);
  129.     PenSize(3, 3);
  130.     InsetRect(&box, -4, -4);
  131.     FrameRoundRect(&box, 16, 16);
  132.     PenNormal();
  133. }
  134.